﻿CREATE PROCEDURE [ServiceEngine].[CreateEndpointUddiAssociation]
	@EndpointID uniqueidentifier,
	@RuntimeServerID uniqueidentifier,
	@ServiceKey nvarchar(64),
	@TModelKey nvarchar(64),
	@BindingKey nvarchar(64),
	@WsdlUrl nvarchar(400),
	@BindingUrl nvarchar(400)
AS
BEGIN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;
	SET NOCOUNT ON;

	BEGIN TRY
		BEGIN TRANSACTION

		DECLARE @ID as uniqueidentifier

		SET @ID = newid();

		INSERT INTO [ServiceEngine].[Endpoints_AssociatedUddi]
				   ([Endpoints_AssociatedUddiID]
				   ,[RuntimeServerID]
				   ,[EndpointID]
				   ,[UddiTModelID]
				   ,[UddiServiceID]
				   ,[UddiBindingID]
				   ,[UddiWsdlUrl]
				   ,[UddiBindingUrl]
				   )
			 VALUES
				   (@ID,@RuntimeServerID,@EndpointID,@TModelKey,@ServiceKey,@BindingKey,@WsdlUrl,@BindingUrl)

		COMMIT TRANSACTION
	END TRY
	BEGIN CATCH
		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;

		RAISERROR (@ErrorMessage, 
				   @ErrorSeverity,
				   1);
	END CATCH
END


